package com.sgb.kjwl.view.ui.adapter.owerInfoNews;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity3;
import com.swgk.core.recyclerview.secondary.CommonHolder;

import java.util.List;

public class OwerInfoNewsTypeAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private int TYPE_ORDER_SUCCESS = 1;
    private int TYPE_ORDER_UNSTART = 2;
    private List<GoodsInfoEntity3> list;

    public OwerInfoNewsTypeAdapter(Context context, List<GoodsInfoEntity3> lists) {
        this.mContext = context;
        this.list = lists;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        if (viewType == TYPE_ORDER_UNSTART) {
            viewHolder = CommonHolder.get(mContext, viewGroup, R.layout.item_owers_message_start3);
        } else if (viewType == TYPE_ORDER_SUCCESS) {
            viewHolder = CommonHolder.get(mContext, viewGroup, R.layout.item_owers_message_success3);
        }
        return viewHolder;
    }

    @Override
    public int getItemViewType(int position) {
        return list.get(position).getGoodsPrice().equals("success") ? TYPE_ORDER_SUCCESS : TYPE_ORDER_UNSTART;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        if (getItemViewType(position) == TYPE_ORDER_SUCCESS) {
            initOrderView((CommonHolder) viewHolder, list.get(position));
        } else if (getItemViewType(position) == TYPE_ORDER_UNSTART) {
            initUnstartView((CommonHolder) viewHolder, list.get(position));
        }
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    private void initOrderView(CommonHolder holder, GoodsInfoEntity3 entity) {
        TextView msDetail = holder.getItem().findViewById(R.id.message_detail);
        TextView msPhone = holder.getItem().findViewById(R.id.message_order_phone);
        TextView msName = holder.getItem().findViewById(R.id.message_order_name);
        ImageView msAvator = holder.getItem().findViewById(R.id.message_avatar);
        TextView msTitle = holder.getItem().findViewById(R.id.message_title);

        String number = "18911789376";
        msPhone.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:" + number + "\""));
            mContext.startActivity(intent);

        });

        msDetail.setOnClickListener(view -> {

        });

    }

    private void initUnstartView(CommonHolder holder, GoodsInfoEntity3 entity) {
        TextView orderDetail = holder.getItem().findViewById(R.id.message_detail);
        TextView orderFrom = holder.getItem().findViewById(R.id.order_from);
        TextView orderTo = holder.getItem().findViewById(R.id.order_to);
        TextView msTitle = holder.getItem().findViewById(R.id.message_title);
        TextView allowPrice = holder.getItem().findViewById(R.id.allow_price);
        TextView otherPrice = holder.getItem().findViewById(R.id.other_price);

        orderDetail.setOnClickListener(view -> {

        });

        allowPrice.setOnClickListener(view -> {

        });

        otherPrice.setOnClickListener(view -> {

        });
    }

}
